using ROC.Resources.Library.Data.Generic;

namespace MoneyManagerPro.Resources.Repository.Users
{
    internal class UserColumnFactory : IDomainObjectFactory<MoneyManagerPro.Business.Entities.User>
    {
        #region IDomainObjectFactory<User> Members

        public MoneyManagerPro.Business.Entities.User Construct(System.Data.IDataReader reader)
        {
            MoneyManagerPro.Business.Entities.User user = new MoneyManagerPro.Business.Entities.User();

            int index;

            index = reader.GetOrdinal("Id");
            if (!reader.IsDBNull(index))
            {
                user.Id = reader.GetInt32(index);
            }

            index = reader.GetOrdinal("FirstName");
            if (!reader.IsDBNull(index))
            {
                user.FirstName = reader.GetString(index);
            }

            index = reader.GetOrdinal("LastName");
            if (!reader.IsDBNull(index))
            {
                user.LastName = reader.GetString(index);
            }

            index = reader.GetOrdinal("UserName");
            if (!reader.IsDBNull(index))
            {
                user.UserName = reader.GetString(index);
            }

            index = reader.GetOrdinal("Password");
            if (!reader.IsDBNull(index))
            {
                user.Password = reader.GetString(index);
            }

            index = reader.GetOrdinal("Email");
            if (!reader.IsDBNull(index))
            {
                user.Email = reader.GetString(index);
            }

            index = reader.GetOrdinal("LastVisit");
            if (!reader.IsDBNull(index))
            {
                user.LastVisit = reader.GetDateTime(index);
            }

            index = reader.GetOrdinal("Description");
            if (!reader.IsDBNull(index))
            {
                user.Description = reader.GetString(index);
            }
            return user;
        }

        #endregion
    }
}
